using BLL;
//using BLL.Bar;
using Entity;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Numerics;
using System.Reflection.Emit;
using System.Security.AccessControl;
using YunProject.Controllers.Base;

namespace YunProject.Controllers
{
    public class BarController : BaseController
    {
        BarBLL barBLL;

        public BarController()
        {
            barBLL = new BarBLL();
        }
        #region
        [Authorize]
        public ActionResult barCodeInfo()
        {
            return View();
        }

        [Authorize]
        public ActionResult barRecords()
        {
            return View();
        }

        [Authorize]
        public ActionResult RecordsList()
        {
            return View();
        }

        [Authorize]
        public ActionResult boxCodeInfo()
        {
            return View();
        }

        [Authorize]
        public ActionResult PrintBar()
        {
            return View();
        }

        [Authorize]
        public ActionResult barCodeSub()
        {
            return View();
        }

        // 生产打码 视图入口
        [Authorize]
        public ActionResult proBarPrint()
        {
            return View();
        }
        // 采购打码 视图入口
        [Authorize]
        public ActionResult purchasePrint()
        {
            return View();
        }
        [Authorize]
        public ActionResult SelectBarCode()
        {
            return View();
        } 
        
        [Authorize]
        public ActionResult SelectBarIn()
        {
            return View();
        }

        #endregion

        /// <summary>
        /// 获取列表数量
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <param name="condition"></param>
        /// <param name="dataType"></param>
        /// <returns></returns>
        [HttpGet]
        public JsonResult GetDataList(string page, string limit, string condition, string dataType)
        {
            string pageCount = "1";
            string msg = "";
            var datas = new object();
            var rsl = new ReturnResult();
            var userObj = LoginInfo();
            if (dataType == "bar")
            {
                //条码档案
                rsl = barBLL.getBarCodeList(page, limit, ref pageCount, condition, "", userObj["baseCode"].ToString());
            }
            else if (dataType == "records")
            {
                rsl = barBLL.getBarEntryRecords(page, limit, ref pageCount, condition);
            }
            else if (dataType == "reList")
            {
                var userInfo = LoginInfo();
                rsl = barBLL.getRecordsListByCode(condition, userInfo["userCode"].ToString());
            }
            // 生产打码
            else if (dataType == "proBarPrint")
            {
                rsl = barBLL.getProBarPrintList(userObj, page, limit, ref pageCount, condition);
            }
            // 采购打码
            else if (dataType == "purchasePrint")
            {
                rsl = barBLL.getPurchasePrintList(userObj, page, limit, ref pageCount, condition);
            }
            else if (dataType == "select")
            {
                rsl = barBLL.getRelationBarCodeList(page, limit, ref pageCount, condition);
            }
            else if (dataType == "srInfo")
            {
                rsl = barBLL.GetSaleRecords(page, limit, ref pageCount, condition);
            }
            
            if (rsl.Result)
            {
                datas = rsl.Data;
            }
            else
            {
                msg = rsl.Message;
            }

            var dic = new Dictionary<string, object>();
            dic["count"] = pageCount;
            dic["msg"] = msg;
            dic["code"] = "0";
            dic["data"] = datas;
            return new JsonResult(dic);


        }

        /// <summary>
        /// 条码作废
        /// </summary>
        /// <param name="page"></param>
        [HttpPost]
        public JsonResult DropBarCode(string barCode)
        {
            var userInfo = LoginInfo();
            return Json(barBLL.DropBarCode(barCode, userInfo["userCode"].ToString(), userInfo["baseCode"].ToString()));
        }
        [HttpPost]
        public JsonResult GetBarCodeInfoByCode(string barCode)
        {
            return Json(barBLL.GetBarCodeInfoByCode(barCode));
        }
        [HttpPost]
        public JsonResult SelectBarIn(string barCodes,string wareHouse)
        {
            var userInfo = LoginInfo();
            return Json(barBLL.SelectBarIn(barCodes, wareHouse, userInfo["userCode"].ToString()));
        }
        
    }
}
